//
//  SixTableViewCell.m
//  QuickReadComic
//
//  Created by 苗钧豪 on 16/9/1.
//  Copyright © 2016年 苗钧豪. All rights reserved.
//

#import "SixTableViewCell.h"
#import "SixCollectionViewCell.h"
#import "TopicsModel.h"
#import "UIImageView+WebCache.h"
#import "MoreViewController.h"
@implementation SixTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    [self NetworkRequests];
    // layout
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
    // Item的大小
    [layout setItemSize:CGSizeMake((self.bounds.size.width - 16) / 3, 190)];
    // 竖向滚动
    [layout setScrollDirection:UICollectionViewScrollDirectionVertical];
    // 内边距
    layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    // 最小列边距行边距
    layout.minimumInteritemSpacing = 8;
    layout.minimumLineSpacing = 8;
    // 给collectionview绑定layout
    [self.sixCollectionView setCollectionViewLayout:layout];
    // 注册cell
    [_sixCollectionView registerNib:[UINib nibWithNibName:@"SixCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"six"];
    // 背景色透明
    _sixCollectionView.backgroundColor = [UIColor clearColor];
    // 是否回弹
    _sixCollectionView.bounces = NO;
    // 指定代理人
    _sixCollectionView.delegate = self;
    _sixCollectionView.dataSource = self;
}
- (void)NetworkRequests {
    [ZWYNetTool GET:@"http://api.kuaikanmanhua.com/v1/topic_new/discovery_list?" andBody:nil andHeader:nil andResponse:ZWYJSON andSuccessBlock:^(id result) {
        NSLog(@"=====================成功啦");
        self.model = [dataModel modelWithDic:result[@"data"]];
        [self.sixCollectionView reloadData];
    } andFailureBlock:^(NSError *error) {
        NSLog(@"=====================出错啦");
    }];
}
// cell数
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 6;
}
// 设置cell
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    SixCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"six" forIndexPath:indexPath];
    NSLog(@"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$%ld",self.Number);
    TopicsModel *topics = self.model.infos[self.Number].topics[indexPath.row];
    NSLog(@"\n\n\n%@",self.model.infos);
    [cell.imgView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",topics.pic]]];
    cell.bookLabel.text = topics.title;
    cell.writerLabel.text = topics.user.nickname;
    return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    MoreViewController *vc = [[MoreViewController alloc]init];
    UINavigationController *navc = [[UINavigationController alloc]initWithRootViewController:vc];
    TopicsModel *topics = self.model.infos[self.Number].topics[indexPath.row];
    CGFloat numb = self.model.infos[self.Number].topics.count;
    vc.descriptionString = topics.descriptions;
    vc.Num = numb;
    vc.imageUrlString = topics.pic;
//    vc.model = topics;
    [UIApplication sharedApplication].keyWindow.rootViewController = navc;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
